package org.example.liaoxuefeng.tongyilingma;

/**
 * @author: 默苍璃
 * @date: 2024-07-17 17:31
 */
public class DeleteCommand implements Command {
    private TextEditor editor;
    private int position;
    private char deletedChar;

    public DeleteCommand(TextEditor editor) {
        this.editor = editor;
        this.position = editor.buffer.length() - 1;
        this.deletedChar = editor.buffer.charAt(position);
    }

    @Override
    public void execute() {
        editor.buffer.deleteCharAt(position);
    }

    @Override
    public void undo() {
        editor.buffer.insert(position, deletedChar);
    }
}
